package com.handinfo.uimenu.window;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.Animation;
import com.handinfo.engine.GameMIDlet;
import com.handinfo.engine.GameManager;
import com.handinfo.game.ActorItem;
import com.handinfo.game.ActorItemConsume;
import com.handinfo.game.ActorItemEquip;
import com.handinfo.game.ActorItemRide;
import com.handinfo.game.ActorRole;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.ArrayList;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;

public class UIBag extends UIAbstractWindow implements ILBHandler
{
	// 状态
	private final int STATE_BASE_NORMAL = 1;// 普通状态
	private final int STATE_BASE_XIANGQIAN = 2;// 镶嵌
	private final int STATE_BASE_MOVE = 3;// 移动
	private final int STATE_BASE_TEACH_EQUIP = 4;// 装备
	private final int STATE_BASE_QIANGHUA = 5;// 强化卷
	// 组,层级
	private final int GROUP_BASE_EQUIP = 1;// 装备
	private final int GROUP_BASE_LABEL = 2;// 标签
	private final int GROUP_BASE_BAG = 3;// 背包
	private final int GROUP_BASE_KUORONG = 4;// 扩容
	private final int GROUP_BASE_TRIM = 5;// 整理
	private final int GROUP_BASE_QIANGHUA = 6;// 强化
	// 索引
	private final int INDEX_BASE_EQUIP_FIRST = 1;
	private final int INDEX_BASE_EQUIP_LAST = INDEX_BASE_EQUIP_FIRST + ActorRole.NUM_BAG_EQUIPMENT - 1;
	private final int INDEX_BASE_LABEL_FIRST = INDEX_BASE_EQUIP_LAST + 1;
	private final int INDEX_BASE_LABEL_LAST = INDEX_BASE_LABEL_FIRST + ActorItemLBHandler.NUM_LABEL_DIS - 1;
	private final int INDEX_BASE_BAG_FIRST = INDEX_BASE_LABEL_LAST + 1;
	private final int INDEX_BASE_BAG_LAST = INDEX_BASE_BAG_FIRST + ActorItemLBHandler.NUM_BAG_DIS - 1;
	private final int INDEX_BASE_KUORONG = INDEX_BASE_BAG_LAST + 1;
	private final int INDEX_BASE_TRIM = INDEX_BASE_KUORONG + 1;
	private final int INDEX_BASE_QIANGHUA = INDEX_BASE_TRIM + 1;
	// 标签字符
	private final Image BUTTON_TRIM = UIManager.IMAGE_LABEL_TRIM;
	private final Image BUTTON_KUORONG = UIManager.IMAGE_LABEL_KUORONG;
	// 弹出菜单字符
	private final String UNINSTALL = "卸载";// 6006 ok
	private final String EQUIP = "装备";// 6006 ok
	private final String DETAIL = "详细说明 ";// 6008 ok
	private final String SENDTOOTHER = "赠送他人";// none
	private final String DESTROY = "销毁";// 6003 ok
	private final String BACK = "返回";// none
	private final String SPLIT = "拆分物品";// 6004 ok
	private final String USE = "使用";// 6002 ok
	private final String MOVE = "移动物品";// 6005 ok
	private final String RIDE = "骑上坐骑";// 6012 ok
	private final String RIDE_CANCEL = "取消坐骑";// 6012 ok
	private final String XIANGQIAN = "镶嵌";//
	private final String HECHENG = "合成";
	private final String TIQU = "提取宝石";
	private final String RESOLVE = "分解";
	private final String QIANGAHUA = "强化";
	private final String JIEBANG = "解绑";
	private final String CHAKANCHENGPIN = "查看成品";
	private final String CHAKANCAILIAO = "查看材料";
	private final String QIANGHUAXIAOCHU = "强化消除";
	private final String WULIXIAOCHU = "物理消除";
	private final String FASHUXIAOCHU = "法术消除";
	private final String FANGJUXIAOCHU = "防具消除";
	// 标题
	private final String TITLE = "背包";
	// 数据
	private ActorItem[] m_items_equip = GameManager.getInstance().m_role.m_bag_equipment;// 仅只当前的装备
	private ActorItem[] m_items_bags = GameManager.getInstance().m_role.m_bag_goods;
	private ActorRole m_role;
	private int m_actionId = 1;
	private int m_frameIndex;
	// 背包处理器
	private ActorItemLBHandler m_bag_handler;
	
	//装备强化消除对象
	private ActorItemEquip m_itemEquip;

	public UIBag(int id)
	{
		super(id);
		setBounds(UITools.X_BG, UITools.Y_BG, UITools.W_BG, UITools.H_BG);
		m_role = GameManager.getInstance().m_role;
		m_bag_handler = new ActorItemLBHandler(this);
		m_bag_handler.setLabelByGroupIndex(0);
	}

	private String[] m_yindao;

	/**
	 * 新手教学 - 裝備道具 2012-3-12 下午10:07:58 venizeng
	 */
	public static void gotoTeachEquip()
	{
		UIBag bag = (UIBag) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_BAG);
		bag.setWindowStatus(bag.STATE_BASE_TEACH_EQUIP);
		String key = UIMain.ID_EQUIP;
		ActorItem[] items = bag.m_items_bags;
		for (int i = 0, length = items.length; i < length; i++) {
			if (items[i] == null) {
				continue;
			}
			if (items[i].m_key.equals(key)) {
				bag.setWindowIndex(bag.INDEX_BASE_BAG_FIRST + i);//
				break;
			}
		}
		bag.m_yindao = Tools.getStrArray("单击选择装备", bag.W_YINDAO - 8);
		UIManager.getInstance().addWindow(bag);
	}

	/**
	 * 进入通用背包 2012-3-12 下午10:08:15 venizeng
	 */
	public static void gotoNormal()
	{
		UIBag bag = (UIBag) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_BAG);
		bag.m_state = bag.STATE_BASE_NORMAL;
		bag.setWindowStatus(bag.STATE_BASE_NORMAL);
		bag.setWindowIndex(bag.INDEX_BASE_BAG_FIRST);
		UIManager.getInstance().addWindow(bag);
	}

	/**
	 * 强化操作
	 */
	public static void gotoStrengenState(ActorItem item)
	{
		UIBag uiBag = (UIBag) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_BAG);
		if (uiBag == null) {
			return;
		}
		uiBag.setWindowStatus(uiBag.STATE_BASE_QIANGHUA);
		uiBag.m_bag_handler.setBagSelIndex(item.m_index);
		uiBag.m_bag_handler.setLabelByLabelId(ActorItem.TYPE_GOODS_EQUIPMENT);
	}
	
	/**
	 * 网络数据更新
	 */
	public void updateWindow()
	{
		m_items_equip = GameManager.getInstance().m_role.m_bag_equipment;
		m_items_bags = GameManager.getInstance().m_role.m_bag_goods;
		m_bag_handler.resetBagData();

		switch (m_state) {
			case STATE_BASE_TEACH_EQUIP:// 接到装备
				setWindowStatus(STATE_BASE_NORMAL);
				break;
			default:
				break;
		}
	}

	// ////////////////////////
	// IWindowHandler
	// ////////////////////////

	protected int countGroupId(int mIndex)
	{
		if (mIndex < INDEX_BASE_LABEL_FIRST) {
			return GROUP_BASE_EQUIP;
		}
		else if (mIndex < INDEX_BASE_BAG_FIRST) {
			return GROUP_BASE_LABEL;
		}
		else if (mIndex < INDEX_BASE_KUORONG) {
			return GROUP_BASE_BAG;
		}
		else if (mIndex < INDEX_BASE_TRIM) {
			return GROUP_BASE_KUORONG;
		}
		else if (mIndex < INDEX_BASE_QIANGHUA) {
			return GROUP_BASE_TRIM;
		}
		else {
			return GROUP_BASE_QIANGHUA;
		}
	}

	protected int countGroupIndex(int mGroupId, int mIndex)
	{
		switch (mGroupId) {
			case GROUP_BASE_EQUIP:
				return mIndex - INDEX_BASE_EQUIP_FIRST;
			case GROUP_BASE_LABEL:
				return mIndex - INDEX_BASE_LABEL_FIRST;
			case GROUP_BASE_BAG:
				return mIndex - INDEX_BASE_BAG_FIRST;
			case GROUP_BASE_KUORONG:
			case GROUP_BASE_TRIM:
			case GROUP_BASE_QIANGHUA:
			default:
				return 0;
		}
	}

	protected void actionOnStateChanged()
	{
		switch (m_state) {
			case STATE_BASE_NORMAL:// 回到普通状态下需要修改当前背包的选中信息
				m_bag_handler.setBagSelIndexNone();
				m_yindao = null;
				break;
			default:
				break;
		}
		
		registerTouch();
	}

	protected void actionOnIndexChanged()
	{
		m_bag_handler.updateOnStateOrIndexChanged();
	}

	// ////////////////////////
	// IBagHandler
	// ////////////////////////
	public Object[] getBagDatas()
	{
		return m_items_bags;
	}

	public int getUpIndex()
	{
		switch (this.m_groupId) {
			case GROUP_BASE_LABEL:
				return INDEX_BASE_EQUIP_FIRST + 4;
			case GROUP_BASE_BAG:
			default:
				switch (this.m_state) {
					case STATE_BASE_NORMAL:
						return m_bag_handler.getCurrentLabelWindowIndex();
					default:
						return AbsLBHandler.TYPE_DIR_UNPRO;
				}
		}
	}

	public int getDownIndex()
	{
		switch (this.m_groupId) {
			case GROUP_BASE_LABEL:
				return INDEX_BASE_BAG_FIRST;
			case GROUP_BASE_BAG:
			default:
				switch (this.m_state) {
					case STATE_BASE_NORMAL:
						return INDEX_BASE_TRIM;
					default:
						return AbsLBHandler.TYPE_DIR_UNPRO;
				}
		}
	}

	public int getLeftIndex()
	{
		switch (this.m_groupId) {
			case GROUP_BASE_LABEL:
				return INDEX_BASE_LABEL_LAST;
			case GROUP_BASE_BAG:
			default:
				switch (this.m_state) {
					case STATE_BASE_NORMAL:
						return m_bag_handler.getCurrentLabelWindowIndex();
					default:
						return AbsLBHandler.TYPE_DIR_UNPRO;
				}
		}
	}

	public int getRightIndex()
	{
		switch (this.m_groupId) {
			case GROUP_BASE_LABEL:
				return INDEX_BASE_LABEL_FIRST;
			case GROUP_BASE_BAG:
			default:
				switch (this.m_state) {
					case STATE_BASE_NORMAL:
						return m_bag_handler.getCurrentLabelWindowIndex();
					default:
						return AbsLBHandler.TYPE_DIR_UNPRO;
				}
		}
	}

	public int getFirstIndex(int idComp)
	{
		switch (idComp) {
			case AbsLBHandler.TYPE_BAG:
				return INDEX_BASE_BAG_FIRST;
			case AbsLBHandler.TYPE_LABEL:
			default:
				return INDEX_BASE_LABEL_FIRST;
		}
	}

	public int getGroupIndex()
	{
		return this.m_groupIndex;
	}

	public int getWindowIndex()
	{
		return this.m_index;
	}

	/***************************/
	// 按键处理
	/***************************/

	protected void keyLogic()
	{
		switch (this.m_state) {
			case STATE_BASE_NORMAL:
				keyLogicOnStateNormal();
				break;
			case STATE_BASE_XIANGQIAN:
				keyLogicOnStateXiangqian();
				break;
			case STATE_BASE_MOVE:
				keyLogicOnStateMove();
				break;
			case STATE_BASE_TEACH_EQUIP:
				keyLogicOnStateEquip();
				break;
			case STATE_BASE_QIANGHUA:
				keyLogicOnStateQianghua();
				break;
		}
	}

	private void keyLogicOnStateQianghua()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			this.setWindowStatus(STATE_BASE_NORMAL);
			return;
		}
		int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_BAG);
		if (dir == AbsLBHandler.TYPE_DIR_NONE) {
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
					|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
				// 镶嵌
				ActorItem dest = (ActorItem) m_bag_handler.getCurrentBagItem();
				if (dest == null) {
					Tools.debugPrintln("在道具上");
					return;
				}
				ActorItem src = m_items_bags[m_bag_handler.getBagSelIndex()];
				GameManager.getInstance().m_game_message.sendActorItemQianghua(dest.m_guid, src.m_guid);
				this.setWindowStatus(STATE_BASE_NORMAL);
				m_bag_handler.setLabelByLabelId(ActorItem.TYPE_GOODS_ALL);
				this.setWindowIndex(INDEX_BASE_BAG_FIRST);
			}
		}
		else if (dir == AbsLBHandler.TYPE_DIR_UNPRO) {
			//
		}
		else {
			this.setWindowIndex(dir);
		}
	}

	/**
	 * 装备背包 2012-3-8 下午03:36:43 venizeng
	 */
	private void keyLogicOnStateEquip()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			clickItemOnStateNormal();// 点击装备
		}
	}

	/**
	 * Normal状态下的按键逻辑
	 */
	protected void keyLogicOnStateNormal()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			close();
			return;
		}
		// 方向键处理
		switch (this.m_groupId) {
			case GROUP_BASE_EQUIP:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
					if (m_groupIndex < 2) {// 0,1
						this.setWindowIndex(INDEX_BASE_TRIM);
					}
					else if (m_groupIndex < 6) {// 2345
						this.setWindowIndex(this.m_index - 2);
					}
					else if (m_groupIndex < 8) {// 6.7
						this.setWindowIndex(INDEX_BASE_TRIM);
					}
					else {
						this.setWindowIndex(this.m_index - 2);
					}
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
					if (m_groupIndex < 4) {// 0,1,2,3
						this.setWindowIndex(this.m_index + 2);
					}
					else if (m_groupIndex < 6) {// 4,5
						this.setWindowIndex(m_bag_handler.getCurrentLabelWindowIndex());
					}
					else if (m_groupIndex < 10) {// 6,7,8,9
						this.setWindowIndex(this.m_index + 2);
					}
					else {
						this.setWindowIndex(m_bag_handler.getCurrentLabelWindowIndex());
					}
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
					if (this.m_groupIndex == 0 || this.m_groupIndex == 2 || this.m_groupIndex == 4) {
						this.setWindowIndex(m_index + 7);
					}
					else if (this.m_groupIndex == 6 || m_groupIndex == 8 || m_groupIndex == 10) {
						this.setWindowIndex(m_index - 5);
					}
					else {
						this.setWindowIndex(m_index - 1);
					}
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
					if (this.m_groupIndex == 7 || this.m_groupIndex == 9 || this.m_groupIndex == 11) {
						this.setWindowIndex(m_index - 7);
					}
					else if (this.m_groupIndex == 1 || m_groupIndex == 3 || m_groupIndex == 5) {
						this.setWindowIndex(m_index + 5);
					}
					else {
						this.setWindowIndex(m_index + 1);
					}
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
					clickItemOnStateNormal();// 点击装备
				}
				break;
			case GROUP_BASE_LABEL: {
				int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_LABEL);
				switch (dir) {
					case AbsLBHandler.TYPE_DIR_UNPRO:
						break;
					case AbsLBHandler.TYPE_DIR_NONE:
						// 未处理
						break;
					default:// 有返回值
						this.setWindowIndex(dir);
						break;
				}
			}
				break;
			case GROUP_BASE_BAG: {
				int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_BAG);
				switch (dir) {
					case AbsLBHandler.TYPE_DIR_UNPRO:
						break;
					case AbsLBHandler.TYPE_DIR_NONE:
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
							clickItemOnStateNormal();
						}
						break;
					default:// 有返回值
						this.setWindowIndex(dir);
						break;
				}
			}
				break;
			case GROUP_BASE_KUORONG:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
					this.setWindowIndex(m_bag_handler.getLastUnLockItemIndex());
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
					this.setWindowIndex(INDEX_BASE_EQUIP_FIRST);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
					this.setWindowIndex(INDEX_BASE_TRIM);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
					this.setWindowIndex(INDEX_BASE_QIANGHUA);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
					actionKuorong();
				}
				break;
			case GROUP_BASE_TRIM:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
					this.setWindowIndex(m_bag_handler.getLastUnLockItemIndex());
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
					this.setWindowIndex(INDEX_BASE_EQUIP_FIRST);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
					this.setWindowIndex(INDEX_BASE_QIANGHUA);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
					this.setWindowIndex(INDEX_BASE_KUORONG);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
					actionTrim();
				}
				break;
			case GROUP_BASE_QIANGHUA: {
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
					this.setWindowIndex(m_bag_handler.getLastUnLockItemIndex());
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
					this.setWindowIndex(INDEX_BASE_EQUIP_FIRST);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
					this.setWindowIndex(INDEX_BASE_KUORONG);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
					this.setWindowIndex(INDEX_BASE_TRIM);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
					UIQianghua.gotoQianghua();
				}
			}
			default:
				break;
		}
	}

	protected void keyLogicOnStateXiangqian()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			this.setWindowStatus(STATE_BASE_NORMAL);
			return;
		}
		int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_BAG);
		if (dir == AbsLBHandler.TYPE_DIR_NONE) {
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
					|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
				// 镶嵌
				ActorItem dest = (ActorItem) m_bag_handler.getCurrentBagItem();
				if (dest == null) {
					Tools.debugPrintln("请镶嵌在道具上");
					return;
				}
				ActorItem src = m_items_bags[m_bag_handler.getBagSelIndex()];
				Tools.debugPrintln("发送镶嵌指令");
				GameManager.getInstance().m_game_message.sendActorItemXiangqian(dest.m_layer_actorItem, src.m_index,
						dest.m_index);
				this.setWindowStatus(STATE_BASE_NORMAL);
				m_bag_handler.setLabelByLabelId(ActorItem.TYPE_GOODS_ALL);
				this.setWindowIndex(INDEX_BASE_BAG_FIRST);
			}
		}
		else if (dir == AbsLBHandler.TYPE_DIR_UNPRO) {
			//
		}
		else {
			this.setWindowIndex(dir);
		}
	}

	protected void keyLogicOnStateMove()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			this.setWindowStatus(STATE_BASE_NORMAL);
			return;
		}
		int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_BAG);
		if (dir == AbsLBHandler.TYPE_DIR_NONE) {
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
					|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
				ActorItem src = m_items_bags[m_bag_handler.getBagSelIndex()];
				if (src == null) {
					return;
				}
				int destIndex = m_bag_handler.getCurrentBagDataIndex();
				if (destIndex == -1) {
					Tools.debugPrintln("uibag keyLogicOnStateMove 移往背包区");
					return;
				}
				if (m_bag_handler.getBagSelIndex() == destIndex) {
					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "移动到同一位置");
				}
				else {
					// 移动到目标位置
					Tools.debugPrintln("移动到目标位置");
					this.setWindowStatus(STATE_BASE_NORMAL);
					GameManager.getInstance().m_game_message.sendActorItemMove(ActorItem.TYPE_BAG_ROLE, src.m_index,
							destIndex);
				}
			}
		}
		else if (dir == AbsLBHandler.TYPE_DIR_UNPRO) {
			//
		}
		else {
			this.setWindowIndex(dir);
		}
	}

	/***************************/
	// 按键处理
	/***************************/

	private String[] getStrings(ActorItem item)
	{
		ArrayList list = new ArrayList(10, 5);
		if (item.isCanUseAtAnyTime()) {
			list.addElement(USE);
		}else {
			if (item.isCanUseAtFight()) {
				list.addElement(USE);
			}
		}
//		Tools.debugPrintln("<<<<<<<<<<<>item.m_type="+item.m_type);
		switch (item.m_type) {
			case ActorItem.TYPE_GOODS_EQUIPMENT:
				ActorItemEquip equip = (ActorItemEquip) item;
				list.addElement(EQUIP);
				if (equip.m_isOperLocked) {
					list.addElement(JIEBANG);
				}
				if (equip.m_isXiangqian_jewels != null) {
					list.addElement(TIQU);
				}
				list.addElement(RESOLVE);
				switch (item.m_type_detail) {
					case ActorItem.TYPE_EQUIPMENT_NECKLACE:// 项链
					case ActorItem.TYPE_EQUIPMENT_RING:// 戒指
					case ActorItem.TYPE_EQUIPMENT_BANGLE:// 手镯
					case ActorItem.TYPE_EQUIPMENT_FABAO:// 法宝
					case ActorItem.TYPE_EQUIPMENT_NICKNAME:// 称号
					case ActorItem.TYPE_EQUIPMENT_DRESS:// 时装
						break;
					default:
						list.addElement(QIANGHUAXIAOCHU);
						break;
				}
				break;
			case ActorItem.TYPE_GOODS_CONSUME:
				if (item.m_isOperLocked) {
					list.addElement(JIEBANG);
				}
				break;
			case ActorItem.TYPE_GOODS_MATERIAL:
				switch (item.m_type_detail) {
					case ActorItem.TYPE_MATERIAL_BAOSHI:// 宝石
						list.addElement(XIANGQIAN);
						list.addElement(HECHENG);
						break;
					case ActorItem.TYPE_MATERIAL_PAPER_BAGUALU:
					case ActorItem.TYPE_MATERIAL_PAPER_TIANGONGFANG:
						list.addElement(CHAKANCHENGPIN);
						list.addElement(CHAKANCAILIAO);
						break;
				}
				if (item.m_isOperLocked) {
					list.addElement(JIEBANG);
				}
				break;
			case ActorItem.TYPE_GOODS_OTHER:
				switch (item.m_type_detail) {
					case ActorItem.TYPE_OTHER_RIDE:
						if (GameManager.getInstance().m_role.m_isride) {
							list.addElement(RIDE_CANCEL);
						}
						else {
							list.addElement(RIDE);
						}
						break;
				}
				if (item.m_isOperLocked) {
					list.addElement(JIEBANG);
				}
				break;
			case ActorItem.TYPE_GOODS_TASK:
				if (item.m_isOperLocked) {
					list.addElement(JIEBANG);
				}
				break;
		}
		list.addElement(DETAIL);
		if (item.m_num > 1) {
			list.addElement(SPLIT);
		}
		list.addElement(MOVE);
		if (!item.m_isOperLocked) {
			list.addElement(SENDTOOTHER);
		}
		list.addElement(DESTROY);
		list.addElement(BACK);
		int size = list.size();
		if (size == 0) {
			return null;
		}
		String[] result = new String[size];
		for (int i = 0; i < result.length; i++) {
			result[i] = (String) list.elementAt(i);
		}
		list.removeAllElements();
		list = null;
		return result;
	}

	private void clickItemOnStateNormal()
	{
		ActorItem item = null;// 获得背包当前格子的道具
		switch (this.m_groupId) {
			case GROUP_BASE_EQUIP:
				item = m_items_equip[getDataIndex(this.m_groupIndex)];
				break;
			case GROUP_BASE_BAG:
				item = (ActorItem) m_bag_handler.getCurrentBagItem();
				break;
		}
		if (item == null) {
			return;
		}
		String[] popmenus = null;
		switch (this.m_groupId) {
			case GROUP_BASE_EQUIP:// 装备格子
				popmenus = new String[] { UNINSTALL, DETAIL, BACK };
				break;
			case GROUP_BASE_BAG:// 背包格子
				popmenus = getStrings(item);
				break;
		}
		if (popmenus == null) {
			return;
		}
		final UIPopmenu popmenu = (UIPopmenu) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_POPMENU);
		popmenu.setPopmenus(popmenus);
		popmenu.addListener(createProcessItemKeyListener(item, popmenu, popmenus));
		UIManager.getInstance().addWindow(popmenu);
	}

	private int getDataIndex(int groupIndex)
	{
		switch (groupIndex) {
			case 0:
			case 1:
				return groupIndex;
			case 2:
			case 3:
				return groupIndex + 2;
			case 4:
			case 5:
				return groupIndex + 4;
			case 6:
			case 7:
				return groupIndex - 4;
			case 8:
			case 9:
				return groupIndex - 2;
			case 10:
			case 11:
				return groupIndex;
		}
		return 0;
	}
    
	private UIListener createProcessItemKeyListener(final ActorItem item, final UIPopmenu popmenu, final String[] menus)
	{
		switch (m_state) {
			case STATE_BASE_NORMAL:
				return new UIListener() {

					public void actionPerformed()
					{
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
							int index = popmenu.getCurrentIndex();
							UIManager.getInstance().removeWindow(popmenu);
							String temp = menus[index];
							if (temp == BACK) {
								actionBack();
							}
							else if (temp == EQUIP) {
								actionEquip(item);
							}
							else if (temp == QIANGAHUA) {
								actionQianghua(item);
							}
							else if (temp == UNINSTALL) {
								actionUninstall(item);
							}
							else if (temp == DETAIL) {
								actionDetail(item);
							}
							else if (temp == SENDTOOTHER) {
								actionSendToOther(item);
							}
							else if (temp == DESTROY) {
								actionDestroy(item);
							}
							else if (temp == SPLIT) {
								actionSplit(item);
							}
							else if (temp == USE) {
								actionUse(item);
							}
							else if (temp == MOVE) {
								actionMove(item);
							}
							else if (temp == RIDE) {
								actionRide((ActorItemRide) item);
							}
							else if (temp == RIDE_CANCEL) {
								actionUnRide((ActorItemRide) item);
							}
							else if (temp == XIANGQIAN) {
								actionXiangqian(item);
							}
							else if (temp == HECHENG) {
								actionHecheng(item);
							}
							else if (temp == TIQU) {
								actionTiqu(item);
							}
							else if (temp == RESOLVE) {
								actionResolve(item);
							}
							else if (temp == JIEBANG) {
								actionJiebang(item);
							}
							else if (temp == CHAKANCHENGPIN){
//								Tools.debugPrintln("><><><><>item name="+item.m_name +";id="+item.m_guid);
								actionChakanchengpin(item);
							}
							else if (temp == CHAKANCAILIAO){
								actionChakancailiao(item);
							}
							else if (temp == QIANGHUAXIAOCHU){
								actionQianghuaXiaoChu(item);
							}
						}
						else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
							UIManager.getInstance().removeWindow(popmenu);
						}
					}

				};
			case STATE_BASE_TEACH_EQUIP:
			default:
				// 阻止它走動
				popmenu.setStop();
				popmenu.setStopMenu(EQUIP);
				UIBag.this.setWindowStatus(STATE_BASE_NORMAL);
				return new UIListener() {

					public void actionPerformed()
					{
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
							UIManager.getInstance().removeWindow(popmenu);
							setWindowStatus(STATE_BASE_NORMAL);
							actionEquip(item);
						}
					}
				};
		}

	}
	
	

	private void actionQianghua(ActorItem item)
	{

	}
	
	private void actionQianghuaXiaoChu(ActorItem item)
	{
		if( item == null ){
			return;
		}	
		if( item instanceof  ActorItemEquip){
			ArrayList list = new ArrayList(3,3);
			m_itemEquip = (ActorItemEquip)item;		
			final long guid = item.m_guid;
			Tools.debugPrintln("<<<<<<<<<<<<<<<<<>>>>>>>>>>  name="+item.m_name);
			final int level = 3;
			if( m_itemEquip.m_level_defence > level ){
				list.addElement(FANGJUXIAOCHU);
			}
			if( m_itemEquip.m_level_phy > level ){
				list.addElement(WULIXIAOCHU);
			}
			if( m_itemEquip.m_level_magic > level ){
				list.addElement(FASHUXIAOCHU);
			}
			list.addElement(BACK);
			if( list.size() <= 1 ){
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "只有强化+3以上装备才可进行消除操作！");
				list.removeAllElements();
				list = null;
				return;
			}
			
			final String[] popmenus = new String[list.size()];
			for (int i = 0; i < popmenus.length; i++) {
				popmenus[i] = (String) list.elementAt(i);
			}
			list.removeAllElements();
			list = null;
			final UIPopmenu popmenu = (UIPopmenu) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_POPMENU);
			popmenu.setPopmenus(popmenus);
			popmenu.addListener(new UIListener() {
				
				public void actionPerformed()
				{
					if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
							|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
						int index = popmenu.getCurrentIndex();
						UIManager.getInstance().removeWindow(popmenu);
						String temp = popmenus[index];
						byte type = 0;
						if (temp == BACK) {
							actionBack();
						}
						else if (temp == WULIXIAOCHU) {
							type = 1;
							GameManager.getInstance().m_game_message.sendToEquipCancel(guid, type);
						}
						else if (temp == FANGJUXIAOCHU) {
							type = 3;
							GameManager.getInstance().m_game_message.sendToEquipCancel(guid, type);
						}
						else if (temp == FASHUXIAOCHU) {
							type = 2;
							GameManager.getInstance().m_game_message.sendToEquipCancel(guid, type);
						}
						
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
						UIManager.getInstance().removeWindow(popmenu);
					}
					
				}
			});
			UIManager.getInstance().addWindow(popmenu);
		}
	}

	/**
	 * 使用
	 * 
	 * @param item
	 */
	private void actionUse(ActorItem item)
	{

		if (item.m_type == ActorItem.TYPE_GOODS_CONSUME) {
			ActorItemConsume consume = (ActorItemConsume) item;
			if (GameManager.getInstance().m_role.isCding(consume.m_cd_type)) {
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "道具Cd时间还未结束");
				return;
			}
		}
		GameManager.getInstance().m_game_message.sendActorItemUse(ActorItem.TYPE_BAG_ROLE, item.m_index);

		// if (!(item instanceof ActorItemConsume)) {
		// return;
		// }
		// ActorItemConsume consume = (ActorItemConsume) item;
		// if (consume.m_type_detail == ActorItem.TYPE_CONSUME_SPEAKER) {// 喇叭
		// // UIChatInsert.gotoServerSpeaker();
		// return;
		// }
		// if (GameManager.getInstance().m_role.isCding(consume.m_cd_type)) {
		// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B,
		// "道具Cd时间还未结束");
		// return;
		// }
		// if (item.isCanUseAtAnyTime()) {// 能在任意时间使用
		// GameManager.getInstance().m_game_message.sendActorItemUse(ActorItem.TYPE_BAG_ROLE,
		// item.m_index);
		// } else {
		// if (GameManager.getInstance().m_role.m_status ==
		// AbstractGameActor.ACTOR_STATUS_ROLE_COMBAT) {// 战斗状态
		// if (item.isCanUseAtFight()) {
		// GameManager.getInstance().m_game_message.sendActorItemUse(ActorItem.TYPE_BAG_ROLE,
		// item.m_index);
		// } else {
		// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B,
		// ActorItem.getOperTypeErrStr(ActorItem.INDEX_TYPE_OPER_USER_AT_FIGHT));
		// }
		// } else {// 非战斗状态，（待确定在其他状态如何使用）
		// GameManager.getInstance().m_game_message.sendActorItemUse(ActorItem.TYPE_BAG_ROLE,
		// item.m_index);
		// }
		// }
	}

	/**
	 * 卸载操作 action 处理popmenu的点击事件
	 */
	private void actionUninstall(final ActorItem item)
	{
		final UIMessageBox box = (UIMessageBox) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MESSAGEBOX);
		box.setMessage("是否确定卸载");
		box.setCentre();
		box.addListener(new UIListener() {
			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT) || AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					UIManager.getInstance().removeWindow(box);
					GameManager.getInstance().m_game_message.sendActorItemUninstall(ActorItem.TYPE_BAG_EQUIP,
							item.m_index);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(box);
				}
			}
		});
	}

	/**
	 * 查看道具详情
	 * 
	 * @param item
	 */
	private void actionDetail(ActorItem item)
	{
		GameManager.getInstance().m_game_message.sendActorItemDetail(item.m_guid);
	}

	/**
	 * 返回
	 */
	private void actionBack()
	{
	}

	/**
	 * 装备
	 * 
	 * @param item
	 */
	private void actionEquip(ActorItem item)
	{
		Tools.debugPrintln("装备道具 -> actionEquip");
		GameManager.getInstance().m_game_message.sendActorItemEquip(ActorItem.TYPE_BAG_ROLE, item.m_index);
	}

	/**
	 * 赠送他人
	 * 
	 * @param item
	 */
	private void actionSendToOther(ActorItem item)
	{
		UIMail.openSendMail(item);
	}

	/**
	 * 销毁
	 * 
	 * @param item
	 */
	private void actionDestroy(final ActorItem item)
	{
		if (item.isCanDrop()) {
			final UIMessageBox box = (UIMessageBox) UIManager.getInstance().createWindow(
					UIWindowFactory.WINDOW_MESSAGEBOX);
			box.setMessage("是否销毁");
			box.setCentre();
			box.addListener(new UIListener() {

				public void actionPerformed()
				{
					if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT) || AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
						UIManager.getInstance().removeWindow(box);
						GameManager.getInstance().m_game_message.sendActorItemDestroy(ActorItem.TYPE_BAG_ROLE,
								item.m_index, item.m_num);
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
						UIManager.getInstance().removeWindow(box);
					}
				}
			});
		}
		else {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B,
					ActorItem.getOperTypeErrStr(ActorItem.INDEX_TYPE_OPER_DROP));
		}
	}

	/**
	 * 移动
	 * 
	 * @param item
	 */
	private void actionMove(ActorItem item)
	{
		this.setWindowStatus(STATE_BASE_MOVE);
		m_bag_handler.setBagSelIndex(item.m_index);
	}

	/**
	 * 镶嵌 点击镶嵌选项
	 * 
	 * @param item
	 */
	private void actionXiangqian(ActorItem item)
	{
		this.setWindowStatus(STATE_BASE_XIANGQIAN);
		m_bag_handler.setBagSelIndex(item.m_index);
		m_bag_handler.setLabelByLabelId(ActorItem.TYPE_GOODS_EQUIPMENT);
	}

	/**
	 * 拆分, 会被Npc等处调用
	 * 
	 * @param item
	 */
	public static final void actionSplit(final ActorItem item)
	{
		if (item == null) {
			return;
		}
		if (item.m_num <= 1) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "道具数目不足以拆分");
			return;
		}
		Form myForm = new Form("输入拆分道具数目");
		myForm.append("当前道具最大数目 :" + item.m_num);
		//
		final TextField textField1 = new TextField("请输入数目", item.m_num - 1 + "", 3, TextField.NUMERIC);
		final StringItem warnInfoItem = new StringItem("", "");
		final Command ok = new Command("确定", Command.OK, 1);
		final Command cancel = new Command("返回", Command.CANCEL, 1);
		//
		myForm.append(textField1);
		myForm.append(warnInfoItem);
		myForm.addCommand(ok);
		myForm.addCommand(cancel);
		//
		CommandListener listener = new CommandListener() {

			public void commandAction(Command c, Displayable d)
			{
				if (c == ok) {
					int num = 0;
					try {
						num = Integer.parseInt(textField1.getString());
					}
					catch (Exception e) {
						warnInfoItem.setText("只能输入数字");
						textField1.setString("");
						return;
					}
					if (num <= 0) {
						warnInfoItem.setText("请输入正确的数目");
						textField1.setString("");
					}
					else if (num >= item.m_num) {
						warnInfoItem.setText("拆分的数目不能大于或等于原有的数目");
						textField1.setString("");
					}
					else {
						// 发送拆分指令
						GameManager.getInstance().m_game_message.sendActorItemDisintegrate(item.m_layer_actorItem,
								item.m_index, num);
						Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
					}
				}
				else if (c == cancel) {
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
			}
		};
		myForm.setCommandListener(listener);
		Display.getDisplay(GameMIDlet.s_instance).setCurrent(myForm);
	}

	/**
	 * 骑乘
	 * 
	 * @param item
	 */
	private void actionRide(ActorItemRide item)
	{
		GameManager.getInstance().m_role.ride(item);
	}

	/**
	 * 卸下坐骑
	 * 
	 * @param item
	 */
	private void actionUnRide(ActorItemRide item)
	{
		if ( GameManager.getInstance().m_role.m_issendride == -1 ) {
			GameManager.getInstance().m_role.m_issendride = 1;
			GameManager.getInstance().m_role.zqIsUseRide(false, null, (byte) -1);
			GameManager.getInstance().m_game_message.sendRideClose();
		}
		// UIBag uiBag = (UIBag)
		// UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_BAG);
		// if (uiBag != null) {
		// UIManager.getInstance().removeWindow(uiBag);
		// }
		UIMenu uiMenu = (UIMenu) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MENU_LR);
		if (uiMenu != null) {
			UIManager.getInstance().removeWindow(uiMenu);
		}
	}

	// private void actionTiqu(final ActorItem item){
	// final UIPopmenu popmenu = (UIPopmenu)
	// UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
	// popmenu.setPopmenus(new String[]{"精密提取","普通提取","返回"}) ;
	// popmenu.addListener(new UIListener() {
	//
	// public void actionPerformed()
	// {
	// if
	// (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)||AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A))
	// {
	// int index = popmenu.getCurrentIndex() ;
	// switch (index) {
	// case 0://"精密提取"
	// actionTiqu1(item) ;
	// break;
	// case 1://"普通提取"
	// actionTiqu2(item) ;
	// break ;
	// default:
	// break;
	// }
	// UIManager.getInstance().removeWindow(popmenu);
	// }else if
	// (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
	// UIManager.getInstance().removeWindow(popmenu);
	// }
	// }
	// }) ;
	// }

	private void actionTiqu(final ActorItem item)
	{
		final UIPopmenu popmenu = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
		popmenu.setPopmenus(new String[] { "精确提取", "普通提取", "返回" });
		popmenu.addListener(new UIListener() {

			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					switch (popmenu.getCurrentIndex()) {
						case 0:// 精确提取
							actionTiqu1(item);
							break;
						case 1:
						actionTiqu2(item);
						break;
					default:
						break;
				}
				UIManager.getInstance().removeWindow(popmenu);
			}
			else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
				UIManager.getInstance().removeWindow(popmenu);
			}
		}
		});
	}

	/**
	 * 普通提取 2012-4-19 下午07:30:19 venizeng
	 * 
	 * @param item
	 */
	private void actionTiqu2(final ActorItem item)
	{
		final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_MESSAGEBOX);
		messageBox.setMessage("提取宝石将损毁道具，但能获得所有宝石，是否提取?");
		messageBox.addListener(new UIListener() {

			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					UIManager.getInstance().removeWindow(messageBox);
					GameManager.getInstance().m_game_message.sendActorItemNorTiqu(item.m_layer_actorItem, item.m_index);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(messageBox);
				}
			}
		});
	}

	/**
	 * 精确
	 * 
	 * @param item
	 */
	private void actionTiqu1(final ActorItem item)
	{
		final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_MESSAGEBOX);
		messageBox.setMessage("精确提取将从道具中获取宝石不会破坏道具,是否提取?");
		messageBox.addListener(new UIListener() {

			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					UIManager.getInstance().removeWindow(messageBox);
					ActorItemEquip equip = (ActorItemEquip) item;
					if (equip.m_color_jewels == null) {
						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "当前道具未镶嵌宝石");
						return;
					}
					int num = 0;// 已经镶嵌的宝石数目
					for (int i = 0; i < equip.m_color_jewels.length; i++) {
						if (!equip.m_isXiangqian_jewels[i]) {
							continue;
						}
						switch (equip.m_color_jewels[i]) {
							case ActorItemEquip.COLOR_JEWEL_RED:
						case ActorItemEquip.COLOR_JEWEL_BLUE:
						case ActorItemEquip.COLOR_JEWEL_GREEN:
						case ActorItemEquip.COLOR_JEWEL_YELLOW:
							num++;
							break;
					}
				}
				if (num == 0) {
					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "当前道具未镶嵌宝石");
					return;
				}
				String[] items = new String[num];
				final byte[] colors = new byte[items.length];
				int index = 0;
				for (int i = 0; i < equip.m_color_jewels.length; i++) {
					if (!equip.m_isXiangqian_jewels[i]) {
						continue;
					}
					switch (equip.m_color_jewels[i]) {
						case ActorItemEquip.COLOR_JEWEL_RED:
							colors[index] = equip.m_color_jewels[i];
							items[index] = ActorItemEquip.NAME_JEWEL_RED;
							index++;
							break;
						case ActorItemEquip.COLOR_JEWEL_BLUE:
							colors[index] = equip.m_color_jewels[i];
							items[index] = ActorItemEquip.NAME_JEWEL_BLUE;
							index++;
							break;
						case ActorItemEquip.COLOR_JEWEL_GREEN:
							colors[index] = equip.m_color_jewels[i];
							items[index] = ActorItemEquip.NAME_JEWEL_GREEN;
							index++;
							break;
						case ActorItemEquip.COLOR_JEWEL_YELLOW:
							colors[index] = equip.m_color_jewels[i];
							items[index] = ActorItemEquip.NAME_JEWEL_YELLOW;
							index++;
							break;
						default:
							break;
					}
				}
				final UIPopmenu popmenu = (UIPopmenu) UIManager.getInstance().createWindow(
						UIWindowFactory.WINDOW_POPMENU);
				popmenu.setPopmenus(items);
				popmenu.addListener(new UIListener() {

					public void actionPerformed()
					{
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
							int index = popmenu.getCurrentIndex();
							UIManager.getInstance().removeWindow(popmenu);
							byte type = colors[index];// 是何种类型的宝石
							int index_real = -1;
							for (int i = 0; i < colors.length; i++) {
								if (type == colors[i]) {
									index_real++;
								}
							}
							GameManager.getInstance().m_game_message.sendActorItemTiqu(item.m_layer_actorItem,
									item.m_index, colors[index_real], index_real);
						}
						else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
							UIManager.getInstance().removeWindow(popmenu);
						}
					}
				});
			}
			else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
				UIManager.getInstance().removeWindow(messageBox);
			}
		}
		});
	}

	/**
	 * 分解 2012-4-16 下午03:13:50 venizeng
	 * 
	 * @param item
	 */
	private void actionResolve(ActorItem item)
	{
		if (item == null) {
			return;
		}
		if (item instanceof ActorItemEquip) {
			ActorItemEquip equip = (ActorItemEquip) item;
			if (!equip.isCanResove()) {// 不能分解
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B,
						ActorItem.getOperTypeErrStr(ActorItem.INDEX_TYPE_OPER_RESOLVE));
				return;
			}
			if (equip.m_color_jewels != null) {// 有宝石，必须先去提取宝石
				for (int i = 0; i < equip.m_color_jewels.length; i++) {
					if (equip.m_isXiangqian_jewels[i]) {
						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "请先提取宝石");
						return;
					}
				}
			}
			GameManager.getInstance().m_game_message.sendActorItemResolve(equip);
		}
	}

	private void actionJiebang(ActorItem item)
	{
		if (item == null) {
			return;
		}
		GameManager.getInstance().m_game_message.sendActorItemJieBang(item);
	}
	
	private void actionChakanchengpin(ActorItem item)
	{
		if (item == null) {
			return;
		}
		GameManager.getInstance().m_game_message.sendActorItemChakanchengpin(item);
	}
	
	private void actionChakancailiao(ActorItem item)
	{
		if (item == null) {
			return;
		}
		GameManager.getInstance().m_game_message.sendActorItemChakancailiao(item);
	}

	/**
	 * 合成
	 * 
	 * @param item
	 */
	private void actionHecheng(final ActorItem item)
	{
		Form myForm = new Form("输入合成宝石的数目");
		myForm.append("当前宝石最大数目 :" + item.m_num);
		//
		final TextField textField1 = new TextField("请输入数目", item.m_num + "", 2, TextField.NUMERIC);
		final StringItem warnInfoItem = new StringItem("", "");
		final Command ok = new Command("确定", Command.OK, 1);
		final Command cancel = new Command("返回", Command.CANCEL, 1);
		//
		myForm.append(textField1);
		myForm.append(warnInfoItem);
		myForm.addCommand(ok);
		myForm.addCommand(cancel);
		CommandListener listener = new CommandListener() {

			public void commandAction(Command c, Displayable d)
			{
				if (c == ok) {
					int num = 0;
					try {
						num = Integer.parseInt(textField1.getString());
					}
					catch (Exception e) {
						warnInfoItem.setText("请输入数字");
						textField1.setString("");
						return;
					}
					if (num == 0) {
						warnInfoItem.setText("请输入正确的数字");
						textField1.setString("");
						return;
					}
					else if (num > item.m_num) {
						warnInfoItem.setText("合成宝石的数目大于原有的数目");
						textField1.setString("");
					}
					else {
						// 发送合成指令
						GameManager.getInstance().m_game_message.sendActorItemHecheng(item.m_index, Integer
								.parseInt(textField1.getString()));
						Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
					}
				}
				else if (c == cancel) {
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
			}
		};
		myForm.setCommandListener(listener);
		Display.getDisplay(GameMIDlet.s_instance).setCurrent(myForm);
	}

	/**
	 * 扩容 - 可能涉及到擴容背包的道具
	 */
	private void actionKuorong()
	{
		actionKuorong("扩充背包需要消耗扩容道具，是否确定扩容");
	}

	/**
	 * 扩容
	 */
	private void actionKuorong(String str)
	{
		final UIMessageBox box = (UIMessageBox) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MESSAGEBOX);
		box.setMessage(str);
		box.addListener(new UIListener() {

			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					UIManager.getInstance().removeWindow(box);
					GameManager.getInstance().m_game_message.sendActorItemKuorong(ActorItem.TYPE_BAG_ROLE);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(box);
				}
			}
		});
	}

	/**
	 * 整理
	 */
	private void actionTrim()
	{
		GameManager.getInstance().m_game_message.sendActorItemTrim(ActorItem.TYPE_BAG_ROLE);
	}

	/***************************/
	// 绘制
	/***************************/
	private int m_x_describe;// 描述的pos
	private int m_y_describe;// 描述的pos
	//
	private final int W_EQUIP = UITools.W_BAG;
	private final int H_EQUIP = UITools.H_BAG;
	private final int IW_EQUIP = 5;// interval W
	private final int IH_EQUIP = 3;
	private final int RW_EQUIP = W_EQUIP + IW_EQUIP;// interval W
	private final int RH_EQUIP = H_EQUIP + IH_EQUIP;
	// pos
	private final int W_EQUIP_ROW = (W_EQUIP << 1) + IW_EQUIP;// 两个道具占据的宽度
	private final int H_EQUIPBAR = RH_EQUIP * 3;
	private final int W_ANIM = UITools.W_ANIM;
	private final int H_ANIM = (H_EQUIPBAR - IH_EQUIP);
	private final int X_ANIM = ((UITools.W_BG - W_ANIM) >> 1);
	private final int X_EQUIP_FIRST = UITools.INITX_CONTENT + ((X_ANIM - UITools.INITX_CONTENT - W_EQUIP_ROW) >> 1);
	private final int X_EQUIP_SECOND = UITools.W_BG - X_EQUIP_FIRST - W_EQUIP_ROW;

	protected void paintContent(Graphics g)
	{
		UITools.paintBackGround(g, m_x, m_y, m_w, m_h, TITLE);
		// #if screen == "640360"
		  int H = 20;
		// #else
//		int H = 0;
		// #endif
		int tempY = m_y + UITools.INITY_CONTENT + H;
		paintEquipBar(g, m_x + X_EQUIP_FIRST, tempY, true);
		paintAnim(g, m_x + X_ANIM, tempY);
		paintEquipBar(g, m_x + X_EQUIP_SECOND, tempY, false);
		tempY += H_EQUIPBAR + H;
		m_bag_handler.setInitXY(tempY);
		m_bag_handler.paintLabel(g);
		m_bag_handler.paintBag(g);
		m_bag_handler.paintDrag(g);
		m_bag_handler.paintBagFocused(g);
		tempY += m_bag_handler.getLBHeight() + UITools.IH_RECT_CONTENT;
		//
		paintMoney(g);
		int tempX = m_x + UITools.IW_WIN;
		tempY = m_y + UITools.ENDY_CONTENT - UITools.H_LABEL;
		paintTrim(g, tempX, tempY);
		tempX += (UITools.IW_RECT_CONTENT + UITools.W_LABEL_MIDDLE);
		paintKuorong(g, tempX, tempY);
		tempX += (UITools.IW_RECT_CONTENT + UITools.W_LABEL_MIDDLE);
		paintQianghua(g, tempX, tempY);
		paintDescribe(g);
		paintYindao(g);
	}

	private void paintMoney(Graphics g)
	{
		int tempX = m_x + m_w - UITools.IW_WIN;//
		int tempY = m_y + UITools.ENDY_CONTENT;
		ActorRole role = GameManager.getInstance().m_role;
		UITools.paintMoneyGameRB(g, tempX, tempY, role.m_money_game, false);
		tempY -= UITools.H_MONEY_GAME;
//		UITools.paintMoneyRmbRB(g, tempX, tempY, role.m_money_rmb, false);
		UITools.paintMoneyYinpiaoRB(g, tempX - UITools.IW_RECTS, tempY, role.m_money_yinpiao, false);

		// UITools.paintMoneyYinpiaoRB(g, tempX, tempY, role.m_money_yinpiao,
		// false);
	}

	// private String[] NAME_EQUIP = new String[] { "头", "胸", "腰", "腿", "足",
	// "武", "饰", "饰", "装", "称", "", "", };
	// private String[] NAME_EQUIP = new String[] { "武", "头", "腰", "胸", "足",
	// "腿", "称", "饰", "宝", "饰", "装", "饰", };
	private byte[] NAME_EQUIP_POS = new byte[] { 5, 0, 2, 1, 4, 3, 8, 6, 9, 6, 7, 6 };

	private void paintEquipBar(Graphics g, int x, int y, boolean isLeft)
	{
		// 半边装备栏
		int tempY = y;
		boolean isFocued = this.m_groupId == GROUP_BASE_EQUIP;
		int index = isLeft ? 0 : 6;
		int dataIndex = isLeft ? 0 : 2;
		for (int i = 0; i < 3; i++) {
			int tempX = x;
			for (int j = 0; j < 2; j++) {
				boolean isFocused = isFocued && this.m_groupIndex == index;
				if (isFocused) {
					m_x_describe = tempX;
					m_y_describe = tempY;
				}
				// UITools.paintActorItem(g, tempX, tempY, m_items_equip[index],
				// false, isFocused, true);
				UITools.paintEquipBar(g, tempX, tempY, m_items_equip[dataIndex + j], false, isFocused, true,
						NAME_EQUIP_POS[index]);
				tempX += RW_EQUIP;
				index++;
			}
			tempY += RH_EQUIP;
			dataIndex += 4;
		}
	}

	private void paintAnim(Graphics g, int tempX, int tempY)
	{
		if (GameManager.getInstance().m_gameStatus == GameManager.GS_UI2) {
			return;
		}
		UITools.paintContentRect(g, tempX, tempY, W_ANIM, H_ANIM);
		try {
			if (m_role == null) {
				Animation animation = GameManager.getInstance().m_shadowAnimation;
				if (animation == null) {
					return;
				}
				animation.draw(g, tempX + (W_ANIM >> 1), tempY + H_ANIM - 3, false, false,
						animation.m_actions[m_actionId][m_frameIndex] & 0x03FF);
			}
			else {
				Animation[] animations = m_role.m_anims;
				if (animations == null) {
					return;
				}
				for (int i = 1; i < animations.length; i++) {
					if (animations[i] == null) {
						continue;
					}
					if (animations[i].m_actions == null) {
						continue;
					}
					if (m_actionId >= animations[i].m_actions.length) {
						continue;
					}
					if (m_frameIndex >= animations[i].m_actions[m_actionId].length) {
						continue;
					}
					if (i == 2 && (animations[1] == GameManager.getInstance().m_shadowAnimation)) {
						
					}else {						
						animations[i].draw(g, tempX + (UITools.W_ANIM >> 1), tempY + H_ANIM - 3, false, false,
								animations[i].m_actions[m_actionId][m_frameIndex] & 0x03FF);
					}
				}
				if (animations[1] == null) {
					return;
				}
				if (animations[1].m_actions == null) {
					return;
				}
				if (m_actionId >= animations[1].m_actions.length) {
					return;
				}
				//
				int num_frame = animations[1].m_actions[m_actionId].length;
				m_frameIndex++;
				if (m_frameIndex >= num_frame) {
					m_frameIndex = 0;
				}
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	private void paintKuorong(Graphics g, int x, int y)
	{
		boolean isSel = this.m_groupId == GROUP_BASE_KUORONG;
		UITools.paintLabelImage(g, x, y, UITools.W_LABEL_MIDDLE, UITools.H_LABEL, BUTTON_KUORONG, isSel, isSel);
	}

	private void paintTrim(Graphics g, int x, int y)
	{
		boolean isSel = this.m_groupId == GROUP_BASE_TRIM;
		UITools.paintLabelImage(g, x, y, UITools.W_LABEL_MIDDLE, UITools.H_LABEL, BUTTON_TRIM, isSel, isSel);
	}

	private void paintQianghua(Graphics g, int x, int y)
	{
		boolean isSel = this.m_groupId == GROUP_BASE_QIANGHUA;
		UITools.paintLabelImage(g, x, y, UITools.W_LABEL_MIDDLE, UITools.H_LABEL, UIManager.IMAGE_BEIBAO_QIANGHUA, isSel, isSel);
	}

	private void paintDescribe(Graphics g)
	{
		switch (this.m_groupId) {
			case GROUP_BASE_EQUIP:
				if (m_items_equip == null) {
					return;
				}
				UITools.paintItemDescribe(g, m_x_describe, m_y_describe, m_w, m_h,
						m_items_equip[getDataIndex(m_groupIndex)]);
				break;
			case GROUP_BASE_BAG: {
				m_bag_handler.paintDescribe(g);
			}
				break;
		}
	}

	private final int W_YINDAO = 80;

	private void paintYindao(Graphics g)
	{
		switch (m_state) {
			case STATE_BASE_TEACH_EQUIP:
				int iw = 4;
				int tempX = 0;
				int tempY = 0;
				int tempW = UIManager.IMAGE_ITEM_OPEN.getWidth() + (iw << 1);
				int tempH = UIManager.IMAGE_ITEM_OPEN.getHeight() + (iw << 1);
				switch (this.m_groupId) {
					case GROUP_BASE_BAG: {
						String temp = "单击选择装备";
						int[] infos = UITools.getYindaoPar2(m_bag_handler.m_x_fos - iw, m_bag_handler.m_y_fos - iw,
								tempW, tempH, m_w, m_h, temp);
						if (infos != null) {
							String[] strs = Tools.getStrArray(temp, infos[11] - (UITools.IW_RECT_CONTENT << 1));
							UITools.paintYindao(g, strs, infos);
						}
						else {
							tempX = m_bag_handler.m_x_fos - iw + tempW;
							tempY = m_bag_handler.m_y_fos - iw + tempH;
							UITools.paintYindao(g, m_yindao, tempX, tempY, W_YINDAO, 2, tempW, tempH);
						}
					}
						break;
				}
				break;
		}
	}
	
	public static void recvComfirmEquipCancel(DataInputStream dis)
	{

		GameManager.getInstance().m_game_message.unlockNetwork();
		try {		
			byte type = dis.readByte();
			if( type == 0){
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "装备强化消除成功！");
			}else{
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "装备强化消除失败！");
			}
		}
		catch (IOException e) {
			Tools.debugPrintln("确定装备强化消除错误！");
		}
	}
	
	public static void recvToEquipCancel(DataInputStream dis)
	{

		GameManager.getInstance().m_game_message.unlockNetwork();
		try {
			UIBag bag = (UIBag) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_BAG);
			ActorItemEquip item = bag.m_itemEquip;
			if (bag == null || item == null) {
				return;
			}
			byte type = dis.readByte();
			long money = dis.readLong();
			Tools.debugPrintln("消除类型："+type);
			int lv = 0;
			String info = "";
			switch(type){
				case 1://物理
					lv = item.m_level_phy;
					info = "物理攻击";
					break;
				case 2://法术
					lv = item.m_level_magic;
					info = "法术攻击";
					break;
				case 3://防御
					lv = item.m_level_defence;
					info = "防具";
					break;
			}
			StringBuffer buff = new StringBuffer();
			buff.append("您的道具：");
			buff.append("+"+lv+item.m_name+"上的"+info+"强化等级将被消除为+0，您可得到消除后返回的金钱");
			int gold = ActorRole.getMoneyGameGold(money);
			if(gold > 0){
				buff.append(""+gold+"金");
			}
			int yin = ActorRole.getMoneyGameSilver(money);
			if( yin > 0){
				buff.append(""+yin+"银");
			}
			int tong = ActorRole.getMoneyGameCopper(money);
			if( tong > 0 ){
				buff.append(""+tong+"铜");
			}
			String temp = buff.toString();
			buff = null;
			bag.isComfirmEquipCancel(type,temp,item);
			
		}
		catch (IOException e) {
			Tools.debugPrintln("请求装备强化消除错误！");
		}
	}
	
	private void isComfirmEquipCancel(final byte type,String temp,final ActorItemEquip item)
	{
		final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_MESSAGEBOX);
		messageBox.setMessage(temp);
		messageBox.addListener(new UIListener() {

			public void actionPerformed()
							{
								if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
									||AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
									UIManager.getInstance().removeWindow(messageBox);
									if( item != null ){
										GameManager.getInstance().m_game_message.sendComfirmEquipCancel(item.m_guid,type);
									}
								}
								else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
									UIManager.getInstance().removeWindow(messageBox);
								}
							}
		});
	}
	
	/**
	 * 扩容提示信息 2012-3-8 下午06:11:19 venizeng
	 * 
	 * @param str
	 */
	public static void recvKuorongAlert(DataInputStream dis)
	{
		String string = "";
		try {
			string = dis.readUTF();
		}
		catch (IOException e) {
			Tools.debugPrintln("扩容信息出错");
		}
		UIBag bag = (UIBag) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_BAG);
		if (bag == null) {
			return;
		}
		bag.actionKuorong(string);
	}
	
	
	
	public String[] m_chakanname;
	public String[] m_chankanid;
	public void recvChakancailiao(DataInputStream dis)
	{
//		UIBag bag = (UIBag) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_BAG);
//		if (bag == null) {
//			return;
//		}
		try {
			byte size = dis.readByte();
			if( size < 0 ){
				return;
			}else{
				m_chakanname = null;
				m_chankanid = null;
				m_chakanname = new String[size+1];
				m_chankanid = new String[size];
				for(int i=0;i<size;i++){
					m_chakanname[i] = dis.readUTF();
					m_chankanid[i] = dis.readUTF();
				}
				m_chakanname[size]  = BACK;
				final UIPopmenu popmenu = (UIPopmenu) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_POPMENU);
				popmenu.setPopmenus(m_chakanname);
				popmenu.addListener(new UIListener(){

					public void actionPerformed()
					{
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
							int index = popmenu.getCurrentIndex();
							if( index >=0 && index < m_chankanid.length ){
								GameManager.getInstance().m_game_message.sendActorItemDetail(m_chankanid[index]);
							}else{
								UIManager.getInstance().removeWindow(popmenu);
							}
						}
						else if(AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)){
							UIManager.getInstance().removeWindow(popmenu);
						}
						
					}
					
				} );
				UIManager.getInstance().addWindow(popmenu);
			}
		}
		catch (IOException e) {
			Tools.debugPrintln("扩容信息出错");
		}

	
	}
/////////////////////////////////////////////////////////////////
	int[][] mequip,mbag,mlabel,mkey;
	protected void registerTouch() {
		clearAllRects();
		registerNormalSoft();
		switch(m_state) {
		case STATE_BASE_NORMAL:
			mequip = new int[12][];
			int H = 20;
			int tempY = m_y + UITools.INITY_CONTENT + H;
			for (int i = 0; i < 3; i++) {
				int tempX = m_x + X_EQUIP_FIRST;
				for (int j = 0; j < 2; j++) {
					mequip[i*2+j] = new int[]{tempX-(IW_EQUIP>>1), tempY-(IW_EQUIP>>1), RW_EQUIP, RH_EQUIP};
					tempX += RW_EQUIP;
				}
				tempY += RH_EQUIP;
			}
			tempY = m_y + UITools.INITY_CONTENT + H;
			for (int i = 0; i < 3; i++) {
				int tempX = m_x + X_EQUIP_SECOND;
				for (int j = 0; j < 2; j++) {
					mequip[i*2+j+6] = new int[]{tempX-(IW_EQUIP>>1), tempY-(IW_EQUIP>>1), RW_EQUIP, RH_EQUIP};
					tempX += RW_EQUIP;
				}
				tempY += RH_EQUIP;
			}
			initTouchRect(mequip);
			
			tempY = m_y + UITools.INITY_CONTENT + H + H_EQUIPBAR + H;
			m_bag_handler.setInitXY(tempY);
			
			mlabel = new int[m_bag_handler.m_num_label][];
			int tempX = m_bag_handler.m_x_label;
			tempY = m_bag_handler.m_y_label;
			for (int i = 0; i < m_bag_handler.m_num_label; i++) {
				mlabel[i] = new int[]{tempX, tempY, m_bag_handler.m_w_label, UITools.H_LABEL};
				tempX += (m_bag_handler.m_w_label + m_bag_handler.m_iw_label);
			}
			initTouchRect(mlabel);
			
			tempY = m_bag_handler.m_y_bag;
			mbag = new int[AbsLBHandler.NUM_BAG_ROW*AbsLBHandler.NUM_BAG_COL][];
			for (int i = 0; i < AbsLBHandler.NUM_BAG_ROW; i++) {
				tempX = m_bag_handler.m_x_bag;
				for (int j = 0; j < AbsLBHandler.NUM_BAG_COL; j++) {
					mbag[i*AbsLBHandler.NUM_BAG_COL+j] = new int[]{tempX, tempY, m_bag_handler.RW_BAG, m_bag_handler.RH_BAG};
					tempX += m_bag_handler.RW_BAG;
				}
				tempY += m_bag_handler.RH_BAG;
			}
			initTouchRect(mbag);
			
			initTouchRect(mkey = new int[][]{
					{53,250,33,22},//kuorong
					{16,250,33,22},//trim
					{90,250,33,22},//qianghua
					///
					{331,172,19,29},//up
					{331,232,19,29},//down
			});
			break;
		}
	}

	protected void onTouchRect(int[][] rect, int touchid) {
		switch (this.m_state) {
		case STATE_BASE_NORMAL:
			if (rect == mequip) {
				if (m_index == touchid+INDEX_BASE_EQUIP_FIRST) {
					GameTouchManager.keyPressedFire();
				} else {
					setWindowIndex(touchid+INDEX_BASE_EQUIP_FIRST);
				}
			} else if (rect == mlabel) {
				if (m_index == touchid+INDEX_BASE_LABEL_FIRST) {
					GameTouchManager.keyPressedFire();
				} else {
					setWindowIndex(touchid+INDEX_BASE_LABEL_FIRST);
				}
			} else if (rect == mbag) {
				if (m_index == touchid+INDEX_BASE_BAG_FIRST) {
					GameTouchManager.keyPressedFire();
				} else {
					setWindowIndex(touchid+INDEX_BASE_BAG_FIRST);
				}
			} else {//mkey
				switch(touchid) {
				case 0:
				case 1:
				case 2:
					if (m_index == touchid+INDEX_BASE_KUORONG) {
						GameTouchManager.keyPressedFire();
					} else {
						setWindowIndex(touchid+INDEX_BASE_KUORONG);
					}
					break;
				case 3:
					GameTouchManager.keyPressedDir(1);
					break;
				case 4:
					GameTouchManager.keyPressedDir(3);
					break;
				}
			}
//			switch (this.m_groupId) {
//			case GROUP_BASE_EQUIP:
//				break;
//			case GROUP_BASE_BAG:
//				break;
//			case GROUP_BASE_KUORONG:
//				break;
//			case GROUP_BASE_LABEL:
//				break;
//			case GROUP_BASE_QIANGHUA:
//				break;
//			case GROUP_BASE_TRIM:
//				break;
//			}
			keyLogicOnStateNormal();
			break;
		case STATE_BASE_XIANGQIAN:
			keyLogicOnStateXiangqian();
			break;
		case STATE_BASE_MOVE:
			keyLogicOnStateMove();
			break;
		case STATE_BASE_TEACH_EQUIP:
			keyLogicOnStateEquip();
			break;
		case STATE_BASE_QIANGHUA:
			keyLogicOnStateQianghua();
			break;
	}
	}
	

}
